package com.suda.catalina.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class LoginActivity extends AppCompatActivity {

    private EditText editText;
    private EditText editText1;
    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        editText = (EditText) findViewById(R.id.editTextName);
        editText1 = (EditText) findViewById(R.id.editTextPassword);

        Bundle bundle = EditShiredPreferences.loadSharedPreferences(LoginActivity.this);
        editText.setText(bundle.get("name").toString());
        editText1.setText(bundle.get("password").toString());
        editText.setSelection(bundle.get("name").toString().length());

        button = (Button) findViewById(R.id.button_login);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("name", editText.getText().toString());
                bundle.putString("password", editText1.getText().toString());
                EditShiredPreferences.saveSharedPreferences(LoginActivity.this, bundle);
                startActivity(new Intent(LoginActivity.this, MainActivity.class));
                finish();
            }
        });
    }
}
